//添加多个参数注意使用[]
layui.use(['form', 'jquery'], function () {

    var form = layui.form,
        $ = layui.jquery;


    var id = sessionStorage.getItem("signRecordId");

    findById(id);

    /**
     * 查询单个
     * @param id
     */
    function findById(id) {

        let result = commonAjax('/sign/findById', {id: id}, 'get');
        setData(result.data);
    }

    /**
     * 赋值
     */
    function setData(data) {
        $('#id').val(data.id);
        $('#username').val(data.username);
        $('input[name=signStatus][value=' + data.signStatus + ']').next().click();
        $('#lateTime').val(data.lateTime);
        //刷新单选框样式
        form.render();
    }

    /**
     * 绑定点击事件
     */
    $('.layui-form-radio').bind('click', function () {
        let signStatus = $("input[name='signStatus']:checked").val();
        let lateTime = $('#lateTime');
        $('#updateTime').val(getNowFormatDate());//修改时间
        if (signStatus === 'late') {
            lateTime.attr('class', "show");
        } else {
            lateTime.attr('class', "hidden");
        }
    });

    /**
     * 保存  //监听提交
     */
     form.on('submit(commit)', function () {
         let data={
             id:$('#id').val(),
             signStatus:$("input[name='signStatus']:checked").val(),
             updateTime: $('#updateTime').val(),
             lateTime: $('#lateTime').val()
         };

         let result = commonAjax('/sign/update',JSON.stringify(data),'post');
         if (result.count === 1) {
             layerMsgSaveSuccess();
         } else {
             layerMsgSaveFail();
         }

         return false;
     });

    /**
     * 关闭窗口
     */
    $('#close').on('click',function () {
        parent.layer.closeAll();
    })
});